/* Copyright 2011 Jonathan Komorek
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jkomorek.eurl.selenium;

import java.util.ArrayList;
import org.openqa.selenium.firefox.FirefoxDriver;

import static org.jkomorek.eurl.selenium.Step.createStep;

/**
 *
 * @author Jonathan Komorek
 */
public class ScriptBuilder {

    private Script script;

    boolean setTitle = false;
    boolean setBaseURL = false;


    public ScriptBuilder() {
        script = new Script();
    }

    public ScriptBuilder setTitle(String title) {
        script.setTitle(title);
        setTitle = true;
        return this;
    }

    public ScriptBuilder setBaseURL(String baseURL) {
        script.setBaseURL(baseURL);
        setBaseURL = true;
        return this;
    }

    public ScriptBuilder addStep(String command, String target, String value) {
        Step step = createStep(script, command, target, value);
        if (script.getSteps() == null) script.setSteps(new ArrayList<Step>());

        script.getSteps().add(step);
        return this;
    }


    public Script done() {
        if( !setTitle ) throw new RuntimeException("Failed to set title when building Script");
        if( !setBaseURL ) throw new RuntimeException("Failed to set baseURL when building Script");

        return script;
    }

}
